using System;
using System.Collections.Generic;
using System.Text;



namespace Weight.Base
{

    public class ResponseResult
    {
        /// <summary>
        /// 状态
        /// </summary>
        public int State { get; set; }

        /// <summary>
        /// 消息内容
        /// </summary>
        public string Message { get; set; }

        /// <summary>
        /// 备用值1
        /// </summary>
        public string Val1 { get; set; }

       /// <summary>
       /// 备用值2
       /// </summary>
        public string Val2 { get; set; }

        /// <summary>
        /// 默认状态
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static ResponseResult Default(string  message =null)
        {
            var result = new ResponseResult();
            result.State = 0;
            result.Message = message;
            return result;
        }


        /// <summary>
        /// 成功状态
        /// </summary>
        /// <param name="message">消息内容</param>
        /// <returns></returns>
        public static ResponseResult Success(string message  = null)
        {
            var result = new ResponseResult();
            result.State = 1;
            result.Message = message;
            return result;
        }


        /// <summary>
        /// 错误状态
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        public static ResponseResult Error(string  message = null)
        {
            var result = new ResponseResult();
            result.State = -1;
            result.Message = message;
            return result;
        }
      
    }

    public class ResponseResult<T> : ResponseResult
        where T : class
    {
        /// <summary>
        /// 业务实体
        /// </summary>
        public T Entity { get; set; }


        /// <summary>
        /// 默认状态
        /// </summary>
        /// <param name="message">消息</param>
        /// <returns></returns>
        public static ResponseResult<T> Default()
        {
            var result = new ResponseResult<T>
            {
                State = 0,
                Message = string.Empty,
                Entity = null
            };
            return result;
        }


        /// <summary>
        /// 成功状态
        /// </summary>
        /// <param name="message">消息</param>
        /// <returns></returns>
        public   static ResponseResult<T> Success(T t,string message = null)
        {
            var result = new ResponseResult<T>
            {
                State = 1,
                Message = message,
                Entity = t
            };
            return result;
        }
        
        /// <summary>
        /// 错误状态
        /// </summary>
        /// <param name="message">消息</param>
        /// <returns></returns>
        public new static ResponseResult<T> Error(string message = null)
        {
            var result = new ResponseResult<T>
            {
                State = -1,
                Message = message,
                Entity = null
            };
            return result;
        }
    }
}


